﻿package com.firewolf.state.states;

import com.firewolf.state.context.GumballMachine;

/**
 * 出糖果状态
 * @author Administrator
 *
 */
public class SoldState implements IState{

	private GumballMachine gumballMachine;
	
	public SoldState(GumballMachine gumballMachine) {
		this.gumballMachine = gumballMachine;
	}
	
	@Override
	public void insert25tMoney() {
		System.out.println("我们正在给你发放糖果！");
	}

	@Override
	public void ejectMoney() {
		System.out.println("对不起，你已经转动了曲柄！");
	}

	@Override
	public void turnCrank() {
		System.out.println("转动两次也不能得到两次糖果！");
	}

	@Override
	public void dispense() {
		gumballMachine.releaseBall();
		if(gumballMachine.getCount()>0){
			gumballMachine.setState(gumballMachine.getNoMoneyState());
		}else{
			System.out.println("糖果发完了---");
			gumballMachine.setState(gumballMachine.getSoldOutState());
		}
	}

}
